<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>w_custom_columns信息列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/style/qbdms.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>
<div class="qbdms-list qbdms-layer-list" style="padding-top: 6px">
    <div>
        <table id="wCustomColumnsTable" lay-filter="wCustomColumnsTable"></table>
    </div>
</div>
<!-- 列表头部工具栏 -->
<script type="text/html" id="wCustomColumnsHeaderToolsBar">
    <div class="ccpui-enterSel">
        <!--<div class="layui-btn-container">-->
            <!---->
            <!--&lt;!&ndash;  <a class="layui-btn layui-btn-sm" lay-event="delete">-->
                  <!--<i class="layui-icon layui-icon-delete"></i>-->
                  <!--<span>删除</span>-->
              <!--</a>&ndash;&gt;-->
        <!--</div>-->
        <form class="layui-form" action="" lay-filter="wCustomColumnsQueryForm">
            <div class="layui-form-body selch">
                <a class="layui-btn layui-btn-sm fillBtn" lay-event="add">
                    <span>新增</span>
                </a>
                <div class="table-top-filter layui-row">
                    <div class="layui-col-md6 layui-col-sm6">
                        <label class="layui-form-label">名称</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input filter-value" name="Q_sign_SL" placeholder="请输入"/>
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-sm6">
                        <label class="layui-form-label">是否默认</label>
                        <div class="layui-input-block">
                            <select name="Q_isDefault_L" class="layui-input filter-value">
                                <option value="">请选择</option>
                                <option value="0">否</option>
                                <option value="1">是</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="selchBtn">
                    <a class="layui-btn layui-btn-sm fillBtn" lay-event="query">
                        <span>查询</span>
                    </a>
                    <div class="layui-btn-group">
                        <button type="button" class="layui-btn layui-btn-sm" lay-event="clears" style="width: 28px;font-size: 12px;padding: 0">
                            <i class="iconfont data-iconcommon_refresh"></i>
                        </button>
                        <!--<button type="button" class="layui-btn layui-btn-sm screenParent" lay-event="screen" style="width: 28px;font-size: 12px;padding: 0">-->
                            <!--<i class="iconfont data-iconcommon_downarrow screen"></i>-->
                        <!--</button>-->
                    </div>
                </div>
            </div>
        </form>
    </div>
</script>
<!-- 右侧工具栏 -->
<script type="text/html" id="wCustomColumnsRightToolsBar">
    <a class="RightBtn" lay-event="edit">编辑</a>
    {{# if(d.isDefault!=null &&  d.isDefault!='1'){ }}
    <a class="RightBtn" lay-event="setDefault">设置默认</a>
    {{# } }}
    <a class="RightBtn" lay-event="setWidth">设置宽度</a>
    <a class="RightBtn" lay-event="del">删除</a>
</script>
<script src="${ctx}/qbdmsStatic/public/configFile.js"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    //一般直接写在一个js文件中
    layui.config({
        base: serverPath.qbdmsPath + staticPath.qbdmsPath //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table', 'setter', 'form', 'common','publicMethods','jquery','layer'], function () {
        var table = layui.table;
        var setter = layui.setter;
        var form = layui.form;
        var common = layui.common;
        var publicMethods = layui.publicMethods;
        var $ = layui.jquery;
        var layer = layui.layer;
        common.tableSort('wCustomColumnsTable');

        var tableH=publicMethods.tabHeight('25');
        var parentUri = parent.location.pathname;
        //筛选条件初始化（页面表格的Id，是否初始化（true、false））
        common.initScreenTop('wQbdTecBasicmanageTable',true);
        //第一个实例
        table.render({
            elem: '#wCustomColumnsTable'
            ,height:tableH
            ,url: serverPath.qbdmsPath + '/qbdms/wCustomColumns/list'
            ,where:{uri:parentUri}
            ,page: true //开启分页
            ,toolbar: '#wCustomColumnsHeaderToolsBar'
            ,defaultToolbar:[]
            ,method: 'post'
            ,autoSort: false //是否排序
            ,cols: [[ //表头
                {type: 'checkbox', fixed: 'left'},
                {field: 'sn', type: 'numbers', title: '序号', fixed: 'left'}
                ,{field: 'fieldJson', title: '字段json',hide:true}
                ,{field: 'sign', title: '名称', csort:false, sortname: 'sign'}
                ,{field: 'isDefault', title: '是否默认',sort:false, sortname: 'is_default',templet: function (d) {
                    if (d.isDefault == '1') {
                        return '是';
                    }else{
                        return '否';
                    }
                }
                }
                ,{
                    field:'gl',
                    width:200,
                    title: '管理',
                    toolbar: '#wCustomColumnsRightToolsBar'
                }
            ]],done:function () {
                common.tableSelectCon('.ccpui-enterSel .layui-form input','a[lay-event=query]','.ccpui-enterSel');
            }
        });

        function reflashQuery(isClear) {
            common.tableConditionRender("wCustomColumnsTable","wCustomColumnsQueryForm",{where:{}},isClear);
        }

        table.on('toolbar(wCustomColumnsTable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            var _this = this;
            switch (obj.event) {
                case 'add':
                    layer.open({
                        type: 2,
                        title: ['新增数据'],
                        skin: 'qbdms-layerFormBtn',
                        area: ['634px', '430px'],
                        content: serverPath.qbdmsPath + "/qbdms/wCustomColumns/view/add"
                    });
                    break;
                case 'delete':
                    var array = "";
                    for (var i = 0; i < data.length; i++) {
                        array+=data[i].id+",";
                    }
                    delFun(data,array);
                    break;
                case "query":
                    reflashQuery(false);
                    break;
                case "clears":
                    reflashQuery(true);
                    break;
                case "screen":
                    common.initScreenTop('wQbdTecBasicmanageTable');
                    break;
            }
        });

        table.on('tool(wCustomColumnsTable)', function(obj) {
            var data = obj.data, //获得当前行数据
                layEvent = obj.event; //获得 lay-event 对应的值
            switch(layEvent){
                case "edit":
                    layer.open({
                        type: 2,
                        area: ['634px', '430px'],
                        skin: 'qbdms-layerFormBtn',
                        title: ['修改数据'],
                        content: serverPath.qbdmsPath + '/qbdms/wCustomColumns/view/add?id='+data.id,
                        success:function (layero, index) {
                            publicMethods.tipsAuto(layero.find('.layui-layer-setwin'),'点击这里关闭弹框哦',2000)
                        }
                    });
                    break;
                case "setDefault":
                    $.ajax({
                        url: serverPath.qbdmsPath + "/qbdms/wCustomColumns/setDefault",
                        type: "post",
                        data: {id:data.id},
                        dataType: 'json',
                        success: function (ret) {
                            layer.alert(ret.msg);
                            //执行重载
                            reflashQuery(true);
                            parent.tableInstace(data.fieldJson);
                        }
                    });
                    break;
                case "del":
                    delFun(data,data.id);
                    break;
                case "setWidth":
                    layer.open({
                        type: 2,
                        title: ['设置列宽'],
                        skin: 'qbdms-layerFormBtn',
                        area: ['630px', '430px'],
                        content: serverPath.qbdmsPath + "/qbdms/wCustomColumns/view/setWidth?id="+data.id,
                        success:function (layero, index) {
                            publicMethods.tipsAuto(layero.find('.layui-layer-setwin'),'点击这里关闭弹框哦',2000)
                        }
                    });
                    break;
            }
        });

        function delFun(ret,id) {
            if (ret.length === 0) {
                layer.msg('请先选择一行数据!',{title: false,skin: 'confirm-class'});
            } else {
                layer.confirm('确定删除当前数据吗?',{title: false,skin: 'confirm-class'}, function (index) {
                    layer.close(index);
                    $.ajax({
                        url: serverPath.qbdmsPath + "/qbdms/wCustomColumns/del",
                        type: "post",
                        data: {id:id},
                        dataType: 'json',
                        success: function (data) {
                            if(ret.isDefault == '1'){
                                var initCols = parent.tableInstace.initCols;
                                if(initCols){
                                    $.each(initCols,function(i,n){
                                        if (typeof n.templet === 'function') {
                                            n.templet = ((n.templet + '').replace(/[\n]/g,""));
                                        }
                                    });
                                    parent.tableInstace(JSON.stringify(initCols));
                                }
                            }
                            layer.alert(data.msg);
                            //执行重载
                            reflashQuery(true);
                        }
                    })
                })
            }
        }
    });
</script>
</body>
</html>